/*
 * @Author: szx
 * @Date: 2021-12-15 14:35:10
 * @LastEditTime: 2021-12-15 14:37:30
 * @Description:
 * @FilePath: \leetcode\100-199\199\199.js
 */
function TreeNode(val, left, right) {
    this.val = val === undefined ? 0 : val;
    this.left = left === undefined ? null : left;
    this.right = right === undefined ? null : right;
}
/**
 * @param {TreeNode} root
 * @return {number[]}
 */
var rightSideView = function (root) {
    const res = [];
    if (!root) return res;
    const que = [];
    que.push(root);
    while (que.length) {
        const length = que.length;
        for (let i = 0; i < length; i++) {
            const tmp = que.shift();
            if (i == 0) res.push(tmp.val);
            if (tmp.right) que.push(tmp.right);
            if (tmp.left) que.push(tmp.left);
        }
    }
    return res;
};
